package com.keruyun.controller;

import com.keruyun.base.jedis.JedisClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.GeoCoordinate;
import redis.clients.jedis.GeoRadiusResponse;

import java.util.List;

@RestController("/geo")
public class GeoController {

    @Autowired
    private JedisClient jedisClient;

    @GetMapping("/point")
    public String addPoint(Double longitude, Double latitude, String name) {
        jedisClient.geoadd("geoTest", new GeoCoordinate(longitude, latitude), name);
        return "success";
    }

    @GetMapping("/radius")
    public List<GeoRadiusResponse> getRadiusPoint(Double longitude, Double latitude, Double radius) {
        return jedisClient.geoRadius("geoTest", new GeoCoordinate(longitude, latitude), radius);
    }

    @GetMapping("/radiusByName")
    public List<GeoRadiusResponse> getRadiusPoint(Double radius, String name) {
        return jedisClient.georadiusByMember("geoTest", name, radius);
    }

}
